"""
Case Type   : datakit安装
Case Name   : 保留天数输入text
Create At   : 2025/4/21
Owner       : @lonely-dance
Description :
    1.查看当前日志保留天数
    2.保留天数输入text
    3.清理环境
Expect      :
    1.成功
    2.合理报错
    3.成功
History     :
"""

import os
import re
import unittest

from yat.test import Node
from yat.test import macro
from testcase.utils.Logger import Logger
from testcase.utils.CommonSH import CommonSH
from testcase.utils.datakit_api.CommonApi import CommonApi


class Tools(unittest.TestCase):
    def setUp(self):
        self.log = Logger()
        self.log.info(f"-----{os.path.basename(__file__)} start-----")
        self.com_sh = CommonSH()
        self.datakit_node = Node('Datakit_Root')
        self.token = self.com_sh.get_token_value(macro.DATAKIT_PASSWD)
        self.log.info(self.token)
        self.assertNotEqual("error", self.token)
        self.com_api = CommonApi(self.token)

    def test_base_ops(self):
        text = '----step1:查看当前日志设置 expect:成功----'
        self.log.info(text)
        response = self.com_api.get_system_log()
        self.log.info(response.json())
        self.assertEqual(200, response.json()['code'], '执行失败')
        self.default_data = response.json()['data']
        self.log.info(self.default_data)

        text = '----step2:保留天数输入text expect:合理报错----'
        self.log.info(text)
        data = {"level": "info", "maxHistory": "五十天", "totalSizeCap": "10gb", "maxFileSize": "5mb"}
        response = self.com_api.post_system_log(data)
        self.log.info(response.json())
        self.assertEqual("request params is bad", response.json()['msg'], '执行失败' + text)

    def tearDown(self):
        self.log.info('----step3:清理环境----')
        response = self.com_api.post_system_log(self.default_data)
        self.log.info(response.json())
        self.assertEqual(200, response.json()['code'], '清理环境失败')
        self.log.info(f"-----{os.path.basename(__file__)} finsh-----")
